#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2e5 + 5;
inline ll read() {
    ll x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
ll T, n, ans;
ll a[N];
bool vis[N];
signed main(void) {
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);
    T = read();
    while (T--) {
        n = read();
        ans = 0;
        for (register int i = 1; i <= n; i++) a[i] = read();
        for (register int i = 1; i <= n; i++) {
            for (register int j = i - 1; j >= 1; j--) {
                if (a[i] == a[j]) {
                    ans += a[i];
                }
            }
        }
        cout << ans << endl;
    }
    return 0;
}
